/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.workhorse.persistence.db4o;

import org.workhorse.persistence.BasePersistenceManager;
import org.workhorse.Identifiable;
import com.db4o.ObjectContainer;
import com.google.inject.Provider;

/**
 * @author Brennan Spies
 *
 * <p></p>
 */
public class Db4oPersistenceManager extends BasePersistenceManager
{
    private ObjectContainer objectContainer;

    /**
     * 
     */
    public Db4oPersistenceManager(Provider<ObjectContainer> ocProvider) {
       objectContainer = ocProvider.get();
    }

    /**
     *
     */
    public void begin() {
        //no-op
    }

    /**
     *
     */
    public void save() {
        objectContainer.commit();
    }

    /**
     *
     */
    public void undo() {
        objectContainer.rollback();
    }

    /**
     *
     * @param object The object to persist
     */
    public void persist(Identifiable object) {
        objectContainer.store(object);
    }

    /**
     *
     * @param object The object to make non-persistent
     */
    public void remove(Object object) {
        objectContainer.delete(object);
    }

    /**
     *
     */
    public void close() {
        objectContainer.close();
    }
}
